package com.jrx.anytxn.transaction.service.impl;

import com.jrx.anytxn.common.data.TxnRespCode;
import com.jrx.anytxn.common.exception.TxnBizException;
import com.jrx.anytxn.common.uitl.BeanMapping;
import com.jrx.anytxn.transaction.dto.loan.AmWaiveRepaymentPlanInfoRes;
import com.jrx.anytxn.transaction.entity.AmWaiveRepaymentPlanInfo;
import com.jrx.anytxn.transaction.mapper.ext.ExtAmWaiveRepaymentPlanInfoMapper;
import com.jrx.anytxn.transaction.service.IWaiveRepaymentPlanInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 贴息还款计划service实现
 *
 * @author yf
 * date 2020/4/13 0013
 * @version V1.0
 **/
@Service
public class WaiveRepaymentPlanInfoServiceImpl implements IWaiveRepaymentPlanInfoService {

    private static final Logger logger = LoggerFactory.getLogger(LoanAccountMainInfoServiceImpl.class);

    @Resource
    private ExtAmWaiveRepaymentPlanInfoMapper extAmWaiveRepaymentPlanInfoMapper;


    @Override
    public List<AmWaiveRepaymentPlanInfoRes> getWaiveRepaymentListByLoanIdAndCusId(String tenantId, String customerId, String loanId) throws TxnBizException {
        List<AmWaiveRepaymentPlanInfo> amWaiveRepaymentPlanInfoList=extAmWaiveRepaymentPlanInfoMapper.selectPlanListByCondSelective(customerId,tenantId,loanId);
        return BeanMapping.copyList(amWaiveRepaymentPlanInfoList,AmWaiveRepaymentPlanInfoRes.class);
    }

    @Override
    public AmWaiveRepaymentPlanInfoRes getWaiveRepaymentInfoByLoanIdAndCusId(String tenantId, String customerId, String loanId, String tenor,String channel) throws TxnBizException {
        AmWaiveRepaymentPlanInfo amWaiveRepaymentPlanInfo=extAmWaiveRepaymentPlanInfoMapper.selectByLoanIdAndTenor(customerId,tenantId,channel,loanId,tenor);
        if(null==amWaiveRepaymentPlanInfo){
            logger.error(TxnRespCode.NOT_EMPTY.getMsg());
            throw new TxnBizException(TxnRespCode.NO_DATA.getCode());
        }
        return BeanMapping.copy(amWaiveRepaymentPlanInfo,AmWaiveRepaymentPlanInfoRes.class);
    }
}
